package cn.laixueit.resource.blog.controller;

import cn.laixueit.po.TbBookChapter;
import cn.laixueit.po.TbBookChapterContent;
import cn.laixueit.resource.BookInterface;
import cn.laixueit.resource.blog.service.TbBookService;
import cn.laixueit.vo.BookVo;
import com.mybatisflex.core.paginate.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Set;

/**
 * @author duxiang
 * @date 2024/2/4 16:07
 */
@RestController
@Slf4j
public class BookController implements BookInterface {

    @Resource
    private TbBookService bookService;

   /* @GetMapping("/blog/findBookCategoryNames")
    public Object findBookCategoryNames(){
        return bookService.findBookCategoryNames();
    }

    @GetMapping("/blog/findBookDate")
    public Object findBookDate(){
        return bookService.findBookDate();
    }*/

    @GetMapping("/blog/randHotBook")
    public Object randHotBook(){
        return bookService.randHotBook();
    }

    @Override
    public Object list() {
        log.error("nihao {}","hhaha");
        return bookService.list();
    }

    @Override
    public Object page(Integer page, Integer size, BookVo bookVo) {
        HashMap<String, Object> map = new HashMap<>();
        Page<BookVo> bookVoPage = bookService.bookPage(page, size, bookVo);
        LinkedHashMap<String, Set<String>> dateMap = bookService.findBookDate(bookVo);
        List<HashMap> categoryNames = bookService.findBookCategoryNames(bookVo);
        map.put("pages",bookVoPage);
        map.put("dateMap",dateMap);
        map.put("categoryNames",categoryNames);
        return map;
    }

    @Override
    public Object save(BookVo bookVo) {
        return bookService.save(bookVo);
    }

    @Override
    public Object remove(String id,Boolean isDelete) {
        return bookService.remove(id,isDelete);
    }

    @Override
    public BookVo findById(String id) {
        return bookService.findById(id);
    }

    @Override
    public BookVo findBookAndChapters(String id) {
        return bookService.findBookAndChapters(id);
    }

    @Override
    public HashMap<String, Object> saveChapter(TbBookChapter chapter) {
        return bookService.saveChapter(chapter);
    }

    @Override
    public List<TbBookChapter> listChapter(String bookId) {
        return bookService.listChapter(bookId);
    }

    @Override
    public Object removeChapter(String chapterId) {
        return bookService.removeChapter(chapterId);
    }

    @Override
    public Object findChapterContent(String chapterId) {
        return bookService.findChapterContent(chapterId);
    }

    @Override
    public Object saveChapterContent(TbBookChapterContent chapterContent) {
        return bookService.saveChapterContent(chapterContent);
    }

    @Override
    public Object findChapters(String bookId) {
        return bookService.findChapters(bookId);
    }
}
